package org.feuyeux.dapr;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.concurrent.TimeUnit;

@SpringBootApplication
@Slf4j
public class HelloDaprApplication implements CommandLineRunner {
    @Override
    public void run(String... args) {
        if (args != null && args.length > 0) {
            String loop = args[0];
            log.info("loop={}", loop);
            if (loop != null) {
                long timeout = Long.parseLong(args[1]);
                for (int i = 0; i < Integer.parseInt(loop); i++) {
                    GreetingDaprClient.hello();
                    try {
                        TimeUnit.MILLISECONDS.sleep(timeout);
                    } catch (InterruptedException e) {
                        log.error("", e);
                    }
                }
            }
        } else {
            GreetingDaprClient.hello();
        }
    }

    public static void main(String[] args) {
        SpringApplication.run(HelloDaprApplication.class, args);
    }
}
